﻿/*
 * Copyright (c) Jason Paul Morley, 2010
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms.Steps
{
    public class ConsiderEdge : Core.IStep
    {
        public ConsiderEdge(Core.Node f, Core.Edge e)
        {
            from = (e.node1 == f ? e.node2 : e.node1 );
            to = (e.node1 == f ? e.node1 : e.node2);
            edge = e;
        }

        private Core.State _pv_oldState1, _pv_oldState2, _pv_oldState3;
        public void Apply()
        {
            _pv_oldState1 = edge.state;
            _pv_oldState2 = from.state;
            _pv_oldState3 = to.state;
            edge.state = Core.State.Highlighted;
            from.state = Core.State.FurtherHighlighted;
            to.state = Core.State.Highlighted;
        }

        public void Undo()
        {
            edge.state = _pv_oldState1;
            from.state = _pv_oldState2;
            to.state = _pv_oldState3;
        }

        public string Name()
        {
            return "Consider: " + from.id + " -> " + to.id;
        }

        public Core.Edge edge;
        public Core.Node from;
        public Core.Node to;


        public void ToNext()
        {
            edge.state = _pv_oldState1;
            from.state = _pv_oldState2;
            to.state = _pv_oldState3;
        }
    }
}
